package com.baselibrary.libs.View.webView;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.baselibrary.libs.R;
import com.baselibrary.libs.Utils.log.LogUtils;
import com.baselibrary.libs.View.baseView.BaseView;

/**
 * Created by 35876 于萌萌
 * 创建日期: 13:42 . 2017年02月02日
 * 描述:封装浏览器
 * <p>
 * <p>
 * 备注:
 */

public class MyWebView extends BaseView{

    private WebView mWebView;

    public MyWebView(Context context) {
        super(context);
    }

    public MyWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public int getXml() {
        return R.layout.my_webview;
    }

    @Override
    public void initView(View view) {
        mWebView = (WebView)view.findViewById(R.id.webview);

    }

    public MyWebView initData_url(String url) {
        mWebView.loadUrl(url);
        WebSettings settings = mWebView.getSettings();
        settings.setJavaScriptEnabled(true);
        mWebView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                LogUtils.i("load开始加载"+System.currentTimeMillis());
            }

            @Override
            public void onLoadResource(WebView view, String url) {
                super.onLoadResource(view, url);
                LogUtils.i("load加载资源" + System.currentTimeMillis());
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                LogUtils.i("load页面完成"+System.currentTimeMillis());
            }
        });

        return this;
    }
}
